package com.yang.designmode.singleton;

/**
 * 懒汉式单例：线程不安全 在需要使用时加载对应的单例对象
 */
public class LazySingleton {
    private static LazySingleton instance;

    private LazySingleton() {

    }

    public static synchronized LazySingleton getInstance() throws InterruptedException {
        //通过构造器完成对象的创建
        if (instance == null) {
            Thread.sleep(10);
            instance = new LazySingleton();
        }
        return instance;
    }
}
